import java.util.*;

public class Main {
    // 字符串通配符
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        while (in.hasNext()) {
            String s1 = in.next().toLowerCase();
            String s2 = in.next().toLowerCase();
            int m = s1.length();
            int n = s2.length();
            boolean[][] flag = new boolean[m+1][n+1];
            flag[0][0] = true;
            for (int i = 1; i < m; i++) {
                if (s1.charAt(i-1) == '*') {
                    flag[i][0] = true;
                } else {
                    break;
                }
            }

            for (int i = 1; i <= m; i++) {
                for (int j = 1; j <= n; j++) {
                    if (s1.charAt(i-1) == s2.charAt(j-1)) {
                        flag[i][j] = flag[i-1][j-1];
                    }

                    if (s1.charAt(i-1) == '?' && ((s2.charAt(j-1) >= '0' && s2.charAt(j-1) <='9')
                    || (s2.charAt(j-1) >= 'a' && s2.charAt(j-1) <= 'z'))) {
                        flag[i][j] = flag[i-1][j-1  ];
                    }

                    if (s1.charAt(i-1) == '*' && ((s2.charAt(j-1) >= '0' && s2.charAt(j-1) <='9')
                            || (s2.charAt(j-1) >= 'a' && s2.charAt(j-1) <= 'z'))) {
                        flag[i][j] = flag[i-1][j-1] || flag[i-1][j] || flag[i][j-1];
                    }
                }
            }
            System.out.println(flag[m][n]);
        }
    }


    // 统计每个月兔子的总数
    public static void main1(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        Map<Integer, Integer> map = new HashMap<>();
        map.put(1, 1);
        map.put(2, 0);
        map.put(3, 0);
        for (int i = 2; i <= n; i++) {
            map.put(3, map.get(3) + map.get(2));
            int tmp = map.get(3);
            map.put(2, map.get(1));
            map.put(1, tmp);
        }
        System.out.println(map.get(1)+map.get(2)+map.get(3));
    }
}
